/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package daoimpl;

import controller.ConnectionMySQL;
import dao.EnderecoDao;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import model.Endereco;

/**
 *
 * @author Rodrigo
 */
public class EnderecoDaoImpl implements EnderecoDao {

    @Override
    public List<Endereco> consultar() {
        String sql = "select * from Endereco";
        List<Endereco> endereco = new ArrayList<>();
        try {
            PreparedStatement ps = ConnectionMySQL.getConnection().prepareStatement(sql);
            ResultSet rs = ps.executeQuery();

            while (rs.next()) {
                Endereco e = new Endereco();
                e.setId(rs.getInt("idendereco"));
                e.setLogadouro(rs.getString("logadouro"));
                e.setBairro(rs.getString("bairro"));
                e.setNumero(rs.getString("numero"));
                e.setCep(rs.getString("cep"));
                e.setCidade(rs.getString("cidade"));

                endereco.add(e);
            }

        } catch (SQLException e) {
            System.out.println("ERROR !");
        }

        return endereco;
    }

}
